package com.lovo.sgproj.dao.imp;

import com.lovo.sgproj.bean.UserBean;
import com.lovo.sgproj.dao.UserDAO;
import com.lovo.sgproj.util.DBUtil;
import org.springframework.stereotype.Component;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

@Component
public class UserDAOImp implements UserDAO {
    @Override
    public UserBean getUserByNamePwd(String f_username, String f_password) {
        UserBean user = null;
        String sql = "select pk_userid from t_user where f_username=? and f_password=?";
        try (Connection con = DBUtil.getConnection();
             PreparedStatement ps = con.prepareStatement(sql)) {
            ps.setString(1, f_username);
            ps.setString(2, f_password);
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                user = new UserBean();
                user.setUserID(rs.getInt("pk_userid"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return user;
    }
}
